﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class BaseData_PayTypeEdit : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("200600106");
        if (!IsPostBack)
        {
            Bind();
        }
    }

    private void Bind()
    {
        if (Request.QueryString["code"] != null)
        {
            Label1.Text = "编辑支付方式";
            string c = Request.QueryString["code"].ToString().Trim();
            if (c == "000" || c == "001" || c == "002" || c == "003" || c == "004")
            {
                btnAddOrUpdate.Text = "不准编辑";
                btnAddOrUpdate.Enabled = false;
            }
            Model.PAYTYPE l = new BLL.PAYTYPE().GetModel(Request.QueryString["code"].ToString());
            txtCode.Text = l.PT_CODE;
            txtCode.Enabled = false;
            txtName.Text = l.PT_NAME;
            ckbACCOUNTPAY.Checked = l.PT_ACCOUNTPAY == 1 ? true : false;
            ckbNOT.Checked = l.PT_NOT == 1 ? true : false;
            ckbONLINE.Checked = l.PT_ONLINE == 1 ? true : false;
            ckbBANK.Checked = l.PT_BANK == 1 ? true : false;
            ckbSTOP.Checked = l.PA_STOP == 1 ? true : false;
            ckbHAVEDEAL.Checked = l.PT_HAVEDEAL == 1 ? true : false;
            txtLOGO.Text = l.PA_LOGO;
            TextBox1.Text = l.PA_NOTE1;
            TextBox2.Text = l.PA_NOTE2;
            TextBox3.Text = l.PA_NOTE3;
            TextBox4.Text = l.PA_ACCOUNT;
            txtSort.Text = l.PA_FIELD1;
            txtFeiLv.Text = l.PA_FIELD2;
            m_myWebTextPane.Text = l.PT_TEXT1;
        }
    }
    protected void btnAddOrUpdate_Click(object sender, EventArgs e)
    {
        Model.PAYTYPE l = new Model.PAYTYPE();
        l.PT_CODE = txtCode.Text.Trim();
        l.PT_NAME = txtName.Text.Trim();
        l.PT_ACCOUNTPAY = ckbACCOUNTPAY.Checked == true ? 1 : 0;
        l.PT_NOT = ckbNOT.Checked == true ? 1 : 0;
        l.PT_ONLINE = ckbONLINE.Checked == true ? 1 : 0;
        l.PT_BANK = ckbBANK.Checked == true ? 1 : 0;
        l.PA_STOP = ckbSTOP.Checked == true ? 1 : 0;
        l.PT_HAVEDEAL = ckbHAVEDEAL.Checked == true ? 1 : 0;
        l.PA_LOGO = txtLOGO.Text.Trim();
        l.PA_NOTE1 = TextBox1.Text.Trim();
        l.PA_NOTE2 = TextBox2.Text.Trim();
        l.PA_NOTE3 = TextBox3.Text.Trim();
        l.PA_ACCOUNT = TextBox4.Text.Trim();
        l.PT_TEXT1 = m_myWebTextPane.Text;
        l.PA_FIELD1 = txtSort.Text.Trim();
        l.PA_FIELD2 = txtFeiLv.Text.Trim();

        if (l.PT_CODE == "" || l.PT_NAME == "")
        {
            Share.Alert(Page, "编号,名称必填！"); return;
        }
        try
        {
            decimal i = Convert.ToDecimal(l.PA_FIELD2);
        }
        catch
        {
            Share.Alert(Page, "费率输入值不正确"); return;
        }
        if (Request.QueryString["code"] != null)
        {
            if (Check.CheckPermission("200600106", "00002"))
            {
                if (new BLL.PAYTYPE().Update(l))
                {
                    Share.InsertLog("200600106", "00002");
                    Response.Redirect("PayType.aspx");
                }
                else
                {
                    Share.Alert(this.Page, "操作失败"); return;
                }
            }
            else
            {
                Share.Alert(this.Page, "无权操作"); return;
            }
        }
        else
        {
            if (Check.CheckPermission("200600106", "00001"))
            {
                if (new BLL.PAYTYPE().Exists(l.PT_CODE))
                {
                    Share.Alert(this.Page, "编号重复"); return;
                }
                else
                {
                    if (new BLL.PAYTYPE().Add(l) != null)
                    {
                        Share.InsertLog("200600106", "00001");
                        Response.Redirect("PayType.aspx");
                    }
                    else
                    {
                        Share.Alert(this.Page, "操作失败"); return;
                    }
                }
            }
            else
            {
                Share.Alert(this.Page, "无权操作"); return;
            }
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("PayType.aspx");
    }
}
